package yxy.game.pm2.command.altar;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.bean.currency.CurrencyType;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.AltarMessage;
import yxy.game.pm2.module.AltarHandle;
import yxy.game.pm2.module.PackageHandle;

/** 祭坛 祭坛 */
@MessageType(proto = Command.Altar, classtype = AltarMessage.AltarRequest.class)
public class CMD_Altar extends Command<AltarMessage.AltarRequest> {

	@Override
	public void execute(MessageSource messageSource, AltarMessage.AltarRequest request) {
		String playerCode = messageSource.getTag();

		AltarMessage.AltarResponse.Builder response = AltarMessage.AltarResponse.newBuilder();

		try {
			response.setPack(new PackageHandle().getPackage(playerCode, CurrencyType.CT_碎片));

			AltarHandle altarHandle = new AltarHandle();
			response.addAllHeros(altarHandle.altarHeros(playerCode));

			send(messageSource, response, Result.Success);
		} catch (Exception e) {
			send(messageSource, response, Result.DataError);
			return;
		}
	}

	private void send(MessageSource messageSource, AltarMessage.AltarResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}